package com.wanmait.translate.utils;


import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public enum AuditEnum {

    TRAVELED_AUDIT("出差审核", Map.of(0,"未审核",1,"已通过",2,"已驳回"));

    //审核类型的名字
    private String typeName;
    //所有可能的状态 状态值：名字
    private Map<Integer,String> states;

    //构造器
    AuditEnum(String typeName, Map<Integer,String> states) {
        this.typeName = typeName;
        this.states = states;
    }


    public String getName(){
        return lineToHump(this.name());
    }
    //静态方法：获得指定类型的指定状态的状态名
    public static String  getStateName(AuditEnum auditEnum,Integer state ){
        return auditEnum.states.get(state);
    }

    //获得当前枚举类所有状态
    public Map<Integer,String> getStates() {
        return states;
    }

    //获得当前类型名
    public String getTypeName() {
        return typeName;
    }



    /**
     * @Author huweibin
     * @Description
     *          根据对应的表id 获得操作的相对url 比如时出差审核
     *         格式为 index/traveledAudit/1
     * @Date 11:25 2020/11/25
     **/
    public String geturl(Integer id){
        //下划线转驼峰
        String type = lineToHump(this.name());
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("index/");
        stringBuilder.append(type+"/");
        stringBuilder.append(id);
        return stringBuilder.toString();
    }
 /*
  * @Author huweibin
  * @Description 下划线转驼峰
  * @Date 11:19 2020/11/25
  **/
    private  String lineToHump(String str) {
        Pattern linePattern = Pattern.compile("_(\\w)");
        str = str.toLowerCase();
        Matcher matcher = linePattern.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    }
}
